﻿<UserControl x:Class="ttg_internal.Utilities.UsageVisualizer.View.DeviceUsageTabView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:convert="clr-namespace:ttg_internal.Utilities.UsageVisualizer.Converter"
    xmlns:custControls="clr-namespace:ttg_internal.Utilities.UsageVisualizer.Other.Controls"
    xmlns:ttg="clr-namespace:ttg_internal.utils;assembly=UtilManager">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/Utilities.Common;component/Styles/DefaultStyles.xaml" />
                <ResourceDictionary Source="/Utilities.Common;component/Styles/CustomStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>

            <!-- Brushes -->
            <DrawingBrush x:Key="GridBackgroundBrush" Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
                <DrawingBrush.Drawing>
                    <DrawingGroup>
                        <DrawingGroup.Children>
                            <GeometryDrawing Geometry="M0,0 L1,0 1,0.1, 0,0.1Z" Brush="Green" />
                            <GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Green" />
                        </DrawingGroup.Children>
                    </DrawingGroup>
                </DrawingBrush.Drawing>
            </DrawingBrush>

            <!-- Data Templates -->
            <DataTemplate DataType="{x:Type ttg:SubSystemInfo}">
                <GroupBox>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="150" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <StackPanel VerticalAlignment="Center" Grid.Column="0">
                            <StackPanel.Resources>
                                <convert:SubsystemIconConverter x:Key="SybsystemIconConverter" />
                            </StackPanel.Resources>

                            <Image Source="{Binding Name, Converter={StaticResource SybsystemIconConverter}}" Height="64" />
                            <TextBlock FontSize="16" HorizontalAlignment="Center" Text="{Binding Name}" />
                        </StackPanel>

                        <Border Background="Black" Grid.Column="1">
                            <Border x:Name="InnerBorder" Background="{StaticResource GridBackgroundBrush}">
                                <Grid>
                                    <Grid.Resources>
                                        <convert:MultiplyConverter x:Key="MultiplyConverter" />
                                    </Grid.Resources>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto" />
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>

                                    <custControls:PumpGraph Percentage="{Binding Usage}" Grid.Column="0" />
                                    <TextBlock FontSize="18" FontWeight="Bold" Foreground="LimeGreen" VerticalAlignment="Center" Opacity="1" TextAlignment="Center"
                                               Text="{Binding Usage, Converter={StaticResource MultiplyConverter}, ConverterParameter=100, StringFormat=\{0:F0\}%}"
                                               Grid.Column="0" />

                                    <ContentControl x:Name="ContentPresenter" HorizontalContentAlignment="Center" Grid.Column="1">
                                        <custControls:HistoryGraph MonitoredValuePath="Usage">
                                            <custControls:HistoryGraph.LayoutTransform>
                                                <ScaleTransform ScaleY="1" ScaleX="{Binding ElementName=ContentPresenter, Path=ActualWidth,
                                                                                    Converter={StaticResource MultiplyConverter},
                                                                                    ConverterParameter=0.005}" />
                                            </custControls:HistoryGraph.LayoutTransform>
                                        </custControls:HistoryGraph>
                                    </ContentControl>
                                </Grid>
                            </Border>
                        </Border>
                    </Grid>
                </GroupBox>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <ItemsControl ItemsSource="{Binding DeviceInfo.SubSystems}" />
</UserControl>
